<!--
 * @Author: H.
 * @Date: 2021-12-06 18:12:03
 * @LastEditTime: 2021-12-14 11:30:22
 * @Description:
-->
<template>
  <div class="category">
    <page-search
      :searchFormConfig="searchFormConfig"
      @queryBtnClick="handleQueryClick"
      @resetBtnClick="handleResetClick"
    ></page-search>
    <page-content
      pageName="category"
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    ></page-content>

    <page-modal
      ref="pageModalRef"
      :defaultInfo="defaultInfo"
      :pageModalConfig="modalConfig"
      pageName="category"
      :pageModalTitle="pageModalTitle"
    ></page-modal>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

import { usePageSearch } from '@/hooks/usePageSearch'
import { usePageModal } from '@/hooks/usePageModal'

import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'
import PageModal from '@/components/page-modal'

import { searchFormConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

export default defineComponent({
  name: 'category',
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()
    // 处理modal的hook
    const editCallback = () => {
      pageModalTitle.value = '编辑类别'
    }
    const newCallback = () => {
      pageModalTitle.value = '新增类别'
    }
    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)

    const pageModalTitle = ref('新增类别')
    return {
      searchFormConfig,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData,
      modalConfig,
      pageModalTitle
    }
  },
  components: {
    PageSearch,
    PageContent,
    PageModal
  }
})
</script>

<style scoped></style>
